<?php include $this->admin_tpl('header');?>
<body>
<form class="layui-form" action="javascript:;">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <ul class="layui-tab-title">
                    <li class="layui-this">常规设置</li>
                    <li>模板设置</li>
                    <li>SEO设置</li>
                </ul>
                <div class="layui-tab-content" style="margin-top: 10px">
                    <div class="layui-tab-item layui-show">
                        <div class="layui-form-item">
                            <label class="layui-form-label">所属上级</label>
                            <div class="layui-input-block">
                                <select name="parent_id" lay-verify="" lay-search>
                                    <option value="0">作为一级菜单</option>
                                    <?php
                        foreach($pidList as $key=>$v){
                                    ?>
                                    <option value="<?php echo $v['id'] ?>" <?php if($data['parent_id']==$v['id']) echo "selected"; ?> ><?php echo $v['name'] ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label required">栏目名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" id="name" lay-verify="required" autocomplete="off"
                                       placeholder="请输入栏目名称"
                                       class="layui-input xv_hanzi" value="<?php echo $data['name']; ?>">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">英文目录</label>
                            <div class="layui-input-block">
                                <input type="text" name="catdir" id="catdir" autocomplete="off"
                                       lay-verify="required|catdir" value="<?php echo $data['catdir']; ?>"
                                       class="layui-input xv_pinyin" placeholder="支持多级目录，如： xinwen/guonei">
                            </div>
                        </div>
                        <div class="layui-form-item huicmf-upload">
                            <label class="layui-form-label">栏目图片</label>
                            <div class="layui-input-block">
                                <input type="text" name="image" value="<?php echo $data['image']; ?>"
                                       onmouseover="hui_img_preview('thumb-select-input',this.value)"
                                       onmouseout="layer.closeAll();" id="thumb-select-input" autocomplete="off"
                                       class="layui-input">
                                <button type="button" class="layui-btn layui-btn-normal webUpload" id="picker_pic"
                                        data-multiple="false" data-input-id="thumb-select-input"
                                        data-preview-id="image" data-type="image"><i class="layui-icon"></i>上传图片
                                </button>
                                <a class="layui-btn"
                                   data-open-pic="<?php echo U('admin/index/file_list',['type'=>'one','select_id'=>'thumb-select-input']) ?>">
                                    <i class="layui-icon">&#xe67c;</i>选择图片
                                </a>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">排序</label>
                            <div class="layui-input-inline">
                                <input type="number" name="sort" id="sort" lay-verify="required" autocomplete="off"
                                       placeholder="请输入菜单排序"
                                       class="layui-input" value="<?php echo $data['sort']; ?>">
                                <tip>【越小越靠前】</tip>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">导航显示</label>
                            <div class="layui-input-block">
                                <input type="radio" name="is_menu" value="1"
                                       title="显示" <?php if($data['is_menu'] == '1') echo "checked" ?>>
                                <input type="radio" name="status" value="0"
                                       title="隐藏" <?php if($data['is_menu'] == '0') echo "checked" ?>>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-block">
                                <input type="radio" name="status" value="1"
                                       title="启用" <?php if($data['status'] == '1') echo "checked" ?>>
                                <input type="radio" name="status" value="0"
                                       title="禁用" <?php if($data['status'] == '0') echo "checked" ?>>
                            </div>
                        </div>
                    </div>
                    <div class="layui-tab-item">
                        暂未开发哦
                    </div>
                    <div class="layui-tab-item">
                        暂未开发哦
                    </div>
                </div>
            </div>

        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <input type="hidden" name="id" value="<?php echo $data['id'] ?>">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="admin-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>

<?php include $this->admin_tpl('footer');?>
<script>
  layui.use(['form', 'jquery', 'miniPinyin'], function () {
    let form = layui.form;
    let $ = layui.jquery;

    form.verify({
      catdir: function (value, item) {
        if (!/^[a-zA-Z0-9_]/.test(value)) {
          return '英文目录不能含有汉字';
        }
        if (/(^\_)|(\__)|(\_+$)/.test(value)) {
          return '英文目录首尾不能出现下划线\'_\'';
        }
        if (/^[0-9]{1}/.test(value)) {
          return '英文目录首字符不能为数字';
        }
      }
    })

    form.on('submit(admin-save)', function (data) {
      $.ajax({
        url: "<?php echo U('admin/category/edit');?>",
        data: JSON.stringify(data.field),
        dataType: 'json',
        contentType: 'application/json',
        type: 'post',
        success: function (res) {
          if (res.code === 200) {
            hui_msg(res.msg, 1, function () {
              window.location.reload();
            });
          } else {
            hui_msg(res.msg, 2);
          }
        }
      })
      return false;
    });

  })
</script>
<script>
</script>
</body>
</html>
